/**
 * 
 */
app = angular.module('mCJ', ['mLogin','ui.bootstrap','LocalStorageModule','ngResource']);

app.run(function(sLogin, $window, $http) {
	sLogin.login();
});

app.config(function ($httpProvider) {
    $httpProvider.interceptors.push('httpRequestInterceptor');
});

app.factory('httpRequestInterceptor', ['$window', 'localStorageService', function($window, localStorageService) {
    return {
        'request': function($config) {
        	if(localStorageService.get('token')) {
        		$config.headers['Authorization'] = 'Bearer ' + localStorageService.get('token');
        	}
        	$config.headers['Content-Type'] = 'application/json';
        	$config.data = '';
            return $config;
        }
//    ,
//    	response : function($config) {
//    		if($config.headers('Authorization')) {
//	    		tStr = $config.headers('Authorization').split(" ");
//				if(tStr[0] == "Bearer") {
//					localStorageService.set('token',tStr[1]);
//				} else {
//					localStorageService.set('token',null);
//					$window.location.href = '/login.html';
//				}
//    		}
//    	}
    };
}]);
